/******************************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd. 		              */
/*																              */
/*	NAME	  = t__sqlserver_bigint_add.c						              */
/*	NOTE	  = 												              */
/*	DATE	  = 2014/11/25 by geyh								              */
/******************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "apmtest_cunit.h"
#include "../test_db2_comm.h"
#include <db2/db2_core.h>
#include <db2/db2_comm.h>
#include <db2/db2_param.h>
#include <db2/db2_obj.h>
#include <db2/config.h>

extern int __db2_set_analysis_data(L7session_db2_private *p_st_private, char *p_data, unsigned int ui_len,
                                   struct timeval *p_st_timestamp, int *p_i_whole_flg);

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    int i_whole_flg = DB2_FALSE;
    int i_ret = APM_L7_ANALYZE_SUCC;
    struct timeval st_timestamp;
    memset(&st_timestamp, 0x0, sizeof(struct timeval));

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    i_ret = __db2_set_analysis_data(p_st_private,
                                    (char *) "\x00\x2b\xd0\x52\x00\x01\x00\x25\x22\x0c\x00\x06\x11\x49\x00\x04\x00\x05\x21\x15\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x0b\xd0\x03\x00\x01\x00\x05\x24\x08\xff",
                                    54, &st_timestamp, &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_TRUE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_RESPONSE);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_TRUE);

    test_db2_destroy_ct(&p_st_conn);
    return;
}

static void __case2(void)
{
    int i_whole_flg = DB2_FALSE;
    int i_ret = APM_L7_ANALYZE_SUCC;
    struct timeval st_timestamp;
    memset(&st_timestamp, 0x0, sizeof(struct timeval));

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    i_ret = __db2_set_analysis_data(p_st_private,
                                    (char *) "\x00\x2b\xd0\x52\x00\x01\x00\x25\x22\x0c\x00\x06\x11\x49\x00\x04\x00\x05\x21\x15\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40",
                                    43, &st_timestamp, &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_FALSE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_RESPONSE);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_FALSE);

    test_db2_destroy_ct(&p_st_conn);
    return;
}

static void __case3(void)
{
    int i_whole_flg = DB2_FALSE;
    int i_ret = APM_L7_ANALYZE_SUCC;
    struct timeval st_timestamp;
    memset(&st_timestamp, 0x0, sizeof(struct timeval));

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    i_ret = __db2_set_analysis_data(p_st_private,
                                    (char *) "\x00\x2b\xd0\x52\x00\x01\x00\x25\x22\x0c\x00\x06\x11\x49\x00\x04\x00\x05\x21\x15\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40",
                                    43, &st_timestamp, &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_FALSE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_RESPONSE);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_FALSE);

    i_ret = __db2_set_analysis_data(p_st_private, (char *) "\x00\x0b\xd0\x03\x00\x01\x00\x05\x24\x08\xff", 11, &st_timestamp,
                                    &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_TRUE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_RESPONSE);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_TRUE);

    test_db2_destroy_ct(&p_st_conn);
    return;
}

static void __case4(void)
{
    int i_whole_flg = DB2_FALSE;
    int i_ret = APM_L7_ANALYZE_SUCC;
    struct timeval st_timestamp;
    memset(&st_timestamp, 0x0, sizeof(struct timeval));

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    i_ret = __db2_set_analysis_data(p_st_private,
                                    (char *) "\x00\x2b\xd0\x52\x00\x01\x00\x25\x22\x0c\x00\x06\x11\x49\x00\x04\x00\x05\x21\x15\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40",
                                    42, &st_timestamp, &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 1);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_FALSE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_RESPONSE);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_FALSE);

    test_db2_destroy_ct(&p_st_conn);
    return;
}

static void __case5(void)
{
    int i_whole_flg = DB2_FALSE;
    int i_ret = APM_L7_ANALYZE_SUCC;
    struct timeval st_timestamp;
    memset(&st_timestamp, 0x0, sizeof(struct timeval));

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    i_ret = __db2_set_analysis_data(p_st_private,
                                    (char *) "\x00\x2b\xd0\x52\x00\x01\x00\x25\x22\x0c\x00\x06\x11\x49\x00\x04\x00\x05\x21\x15\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40",
                                    42, &st_timestamp, &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 1);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_FALSE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_RESPONSE);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_FALSE);

    i_ret = __db2_set_analysis_data(p_st_private, (char *) "\x40\x00\x0b\xd0\x03\x00\x01\x00\x05\x24\x08\xff", 12, &st_timestamp,
                                    &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_TRUE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_RESPONSE);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_TRUE);

    test_db2_destroy_ct(&p_st_conn);
    return;
}

static void __case6(void)
{
    int i_whole_flg = DB2_FALSE;
    int i_ret = APM_L7_ANALYZE_SUCC;
    struct timeval st_timestamp;
    memset(&st_timestamp, 0x0, sizeof(struct timeval));

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    i_ret = __db2_set_analysis_data(p_st_private, (char *) "\x00\x2b\xd0\x52\x00\x01\x00\x25\x22\x0c", 10, &st_timestamp,
                                    &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 33);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_FALSE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_RESPONSE);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_FALSE);

    test_db2_destroy_ct(&p_st_conn);
    return;
}

static void __case7(void)
{
    int i_whole_flg = DB2_FALSE;
    int i_ret = APM_L7_ANALYZE_SUCC;
    struct timeval st_timestamp;
    memset(&st_timestamp, 0x0, sizeof(struct timeval));

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    i_ret = __db2_set_analysis_data(p_st_private, (char *) "\x00\x2b\xd0\x52\x00\x01\x00\x25\x22\x0c", 10, &st_timestamp,
                                    &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 33);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_FALSE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_RESPONSE);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_FALSE);

    i_ret = __db2_set_analysis_data(p_st_private,
                                    (char *) "\x00\x06\x11\x49\x00\x04\x00\x05\x21\x15\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40",
                                    32, &st_timestamp, &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 1);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_FALSE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_RESPONSE);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_FALSE);

    test_db2_destroy_ct(&p_st_conn);
    return;
}

static void __case8(void)
{
    int i_whole_flg = DB2_FALSE;
    int i_ret = APM_L7_ANALYZE_SUCC;
    struct timeval st_timestamp;
    memset(&st_timestamp, 0x0, sizeof(struct timeval));

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    i_ret = __db2_set_analysis_data(p_st_private, (char *) "\x00\x2b", 2, &st_timestamp, &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 2);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_FALSE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_UNKNOW);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_FALSE);

    test_db2_destroy_ct(&p_st_conn);
    return;
}

static void __case9(void)
{
    int i_whole_flg = DB2_FALSE;
    int i_ret = APM_L7_ANALYZE_SUCC;
    struct timeval st_timestamp;
    memset(&st_timestamp, 0x0, sizeof(struct timeval));

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    i_ret = __db2_set_analysis_data(p_st_private, (char *) "\x00\x2b", 2, &st_timestamp, &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 2);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_FALSE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_UNKNOW);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_FALSE);

    i_ret = __db2_set_analysis_data(p_st_private,
                                    (char *) "\xd0\x52\x00\x01\x00\x25\x22\x0c\x00\x06\x11\x49\x00\x04\x00\x05\x21\x15\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x0b\xd0\x03\x00\x01\x00\x05\x24\x08",
                                    51, &st_timestamp, &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 1);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_TRUE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_RESPONSE);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_FALSE);

    test_db2_destroy_ct(&p_st_conn);
    return;
}

static void __case10(void)
{
    int i_whole_flg = DB2_FALSE;
    int i_ret = APM_L7_ANALYZE_SUCC;
    struct timeval st_timestamp;
    memset(&st_timestamp, 0x0, sizeof(struct timeval));

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    i_ret = __db2_set_analysis_data(p_st_private, (char *) "\x00\x2b", 2, &st_timestamp, &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 2);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_FALSE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_UNKNOW);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_FALSE);

    i_ret = __db2_set_analysis_data(p_st_private,
                                    (char *) "\xd0\x52\x00\x01\x00\x25\x22\x0c\x00\x06\x11\x49\x00\x04\x00\x05\x21\x15\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x0b\xd0\x03\x00\x01\x00\x05\x24\x08",
                                    51, &st_timestamp, &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 1);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_TRUE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_RESPONSE);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_FALSE);

    i_ret = __db2_set_analysis_data(p_st_private, (char *) "\xff", 1, &st_timestamp, &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_TRUE);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_req_resp_flg, DB2_RESPONSE);
    CU_ASSERT_EQUAL(i_whole_flg, DB2_TRUE);

    test_db2_destroy_ct(&p_st_conn);
    return;
}

static void __case11(void)
{
    int i_whole_flg = DB2_FALSE;
    int i_ret = APM_L7_ANALYZE_SUCC;
    struct timeval st_timestamp;
    memset(&st_timestamp, 0x0, sizeof(struct timeval));

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    i_ret = __db2_set_analysis_data(p_st_private, (char *) "\x00\x2b\xd0\x52\x00\x01\x00\x25\x22\x0c", 10, &st_timestamp,
                                    &i_whole_flg);

    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->u64_remain_len, 33);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_residual_ddm_head_len, 0);
    CU_ASSERT_EQUAL(p_st_private->p_st_fragment->i_last_ddm_flg, DB2_FALSE);

    i_ret = __db2_set_analysis_data(p_st_private,
                                    (char *) "\x00\x06\x11\x49\x00\x04\x00\x05\x21\x15\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40",
                                    35, &st_timestamp, &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    test_db2_destroy_ct(&p_st_conn);
    return;
}

static void __case12(void)
{
    int i_whole_flg = DB2_FALSE;
    int i_ret = APM_L7_ANALYZE_SUCC;
    struct timeval st_timestamp;
    memset(&st_timestamp, 0x0, sizeof(struct timeval));

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    i_ret = __db2_set_analysis_data(p_st_private,
                                    (char *) "\x00\x2b\xd0\x52\x00\x01\x00\x25\x22\x0c\x00\x06\x11\x49\x00\x04\x00\x05\x21\x15\x01\x00\x16\x21\x10\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x0b\xd0\x03\x00\x02\x00\x05\x24\x08\xff",
                                    54, &st_timestamp, &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    test_db2_destroy_ct(&p_st_conn);
    return;
}

int add_suite__db2_set_analysis_data(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __db2_set_analysis_data()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL ||
        CU_add_test(pSuite, "case5", __case5) == NULL ||
        CU_add_test(pSuite, "case6", __case6) == NULL ||
        CU_add_test(pSuite, "case7", __case7) == NULL ||
        CU_add_test(pSuite, "case8", __case8) == NULL ||
        CU_add_test(pSuite, "case9", __case9) == NULL ||
        CU_add_test(pSuite, "case10", __case10) == NULL ||
        CU_add_test(pSuite, "case11", __case11) == NULL ||
        CU_add_test(pSuite, "case12", __case12) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
